package com.cg.controller.business;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cg.controller.AbstractController;
import com.cg.entity.BaseBusiness;
import com.cg.entity.BusinessDoc;
import com.cg.entity.SysRoleEntity;
import com.cg.service.impl.BusinessDocServiceImpl;
import com.cg.utils.Constant;
import com.cg.utils.DateUtils;
import com.cg.utils.Query;
import com.cg.utils.R;
import com.cg.utils.annotation.SysLog;

/**
 * 
 * @author cumt
 *
 */
@RestController
@RequestMapping("/sys/businessdoc")
public class BusinessDocController extends AbstractController{
	@Autowired
	BusinessDocServiceImpl businessDocServiceImpl;
	/**
	 * 所有列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sys:businessdoc:list")
	public R list(@RequestParam Map<String, Object> params){
		//只有超级管理员，才能查看所有管理员列表
		if(getUserId() != Constant.SUPER_ADMIN){
			params.put("createUserId", getUserId());
		}
		
		//查询列表数据
		Query query = new Query(params);
//		
//		BusinessDoc doc=new BusinessDoc();
		List<BusinessDoc> businessList = businessDocServiceImpl.queryList(query);
		int total = businessDocServiceImpl.queryTotal(query);
		
		//PageUtils pageUtil = new PageUtils(userList, total, query.getLimit(), query.getPage());
		
		return R.success(total, "", businessList);
	}
	
	/**
	 * 业务列表
	 */
	@RequestMapping("/select")
	@RequiresPermissions("sys:businessdoc:select")
	public R select(){
//		BusinessDoc doc=new BusinessDoc();
		
		Map<String, Object> doc = new HashMap<>();
		List<BusinessDoc> list = businessDocServiceImpl.queryList(doc );
		
		return R.ok().put("list", list);
	}
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sys:businessdoc:info")
	public R info(@PathVariable("id") Long id){
		BusinessDoc doc = businessDocServiceImpl.queryObject(id);
		
		
		return R.ok().put("doc", doc);
	}
	
	
	/**
	 * 保存用户
	 */
	@SysLog("保存")
	@RequestMapping("/save")
	@RequiresPermissions("sys:businessdoc:save")
	public R save(@RequestBody BusinessDoc doc){
		doc.setCreateTime(DateUtils.dateToDateString(new Date()));
		businessDocServiceImpl.save(doc);
		
		return R.ok();
	}
	/**
	 * 修改用户
	 */
	@SysLog("修改")
	@RequestMapping("/update")
	@RequiresPermissions("sys:businessdoc:update")
	public R update(@RequestBody BusinessDoc doc){
		
//		comment.set(getUserId());
		businessDocServiceImpl.update(doc);
		
		return R.ok();
	}
	
	/**
	 * 删除用户
	 */
	@SysLog("删除")
	@RequestMapping("/delete")
	@RequiresPermissions("sys:basebusiness:delete")
	public R delete(@RequestBody Long[] ids){
		
		businessDocServiceImpl.deleteBatch(ids);
		
		return R.ok();
	}
	
}
